﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System
{
    public static class DateTimeExtention
    {
        /// <summary>
        /// 获取时间戳(到秒)
        /// </summary>
        /// <param name="time"></param>
        /// <param name="isUniversal">是否以世界时间为准</param>
        /// <returns></returns>
        public static long GetTimestamp(this DateTime time, bool isUniversal = false)
        {
            if (isUniversal)
                return (long)(time.ToUniversalTime() - OriginalTime).TotalSeconds;
            else
                return (long)(time - OriginalTime).TotalSeconds;
        }

        public static long GetTimestampWithMilliseconds(this DateTime time, bool isUniversal = false)
        {
            if (isUniversal)
                return (long)(time.ToUniversalTime() - OriginalTime).TotalMilliseconds;
            else
                return (long)(time - OriginalTime).TotalMilliseconds;
        }

        /// <summary>
        /// 获取农历时间结构
        /// </summary>
        /// <param name="time"></param>
        /// <returns></returns>
        public static Lunar GetLunarData(this DateTime time)
        {
            return LunarAPI.GetLunarDate(time);
        }


        private static readonly DateTime OriginalTime = new DateTime(1970, 1, 1, 0, 0, 0, 0);

    }
}
